<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增服务商尾款充值抵扣')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-AgentApplyTailmoney-add" enctype="multipart/form-data">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">申请服务商：</label>
                <div class="col-sm-8">
                    <input id="agentNum" name="agentNum"  placeholder="选择服务商" class="form-control" type="text" required readonly onclick="getAgentInfo()">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">服务商名称：</label>
                <div class="col-sm-8">
                    <input type="text" id="agentName" name="agentName" class="form-control"  required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">未结清尾款：</label>
                <div class="col-sm-8">
                    <input id="surplusMoney" name="surplusMoney" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">申请金额：</label>
                <div class="col-sm-8">
                    <input name="applyMoney" id="applyMoney" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">支付凭证：</label>
                <div class="col-sm-8">
                    <input name="imgFile" id="imgFile" class="form-control" type="file" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "AgentApplyTailmoney/AgentApplyTailmoney"

        function submitHandler() {
            if ($.validate.form()) {
                var data = new FormData();
                //加入文件对象 需要自定义处理不是file类型的参数
                data.append("imgFile", document.getElementById("imgFile").files[0]);
                data.append("agentNum", $("#agentNum").val());
                data.append("agentName", $("#agentName").val());
                data.append("applyMoney", $("#applyMoney").val());
                data.append("surplusMoney", $("#surplusMoney").val());
                $.ajax({
                    url: prefix + "/saveApplyTMoney",
                    data: data,
                    type: "post",
                    dataType: "json",
                    cache: false,//上传文件无需缓存
                    processData: false,//用于对data参数进行序列化处理 这里必须false
                    contentType: false, //必须
                    success: function (result) {
                        if (result.code == '0') {
                            $.operate.successCallback(result);
                        }else {
                            $.modal.alertError(result.msg);
                        }
                    },
                })
            }
        }

        /**
         * 选择服务商
         */
        function getAgentInfo() {
            $.modal.open("选择服务商", ctx + "AgentApplyTailmoney/AgentApplyTailmoney/infoView","600","300");
        }
    </script>



</body>
</html>